package imnu.innner.oop;

/**
 * @author: lys
 * @类名: Student
 * @Title: 内部类
 * @date: 2020/7/16
 **/
public class Student {
    //定义属性
    private int stuId;
    private String stuName;
    private boolean stuSex;

    //定义成员内部类
    class Game{
        public void doSomething(){
            System.out.println("我是成员内部类。");
        }

    }
    //方法
    public void studing(){
        System.out.println("我在学习。");
        Game g = new Game();
        g.doSomething();
    }
    public void eatting(){
        //局部内部类
        class Sleep{
            public void doSomething(){
                System.out.println("我是局部内部类。");
            }
        }
        System.out.println("我在吃饭。");
        Sleep sleep = new Sleep();
        sleep.doSomething();

    }

    //构造方法
    public Student(){}
    public Student(int stuId, String stuName, boolean stuSex) {
        this.stuId = stuId;
        this.stuName = stuName;
        this.stuSex = stuSex;
    }

    //getter和setter方法
    public int getStuId() {
        return stuId;
    }

    public void setStuId(int stuId) {
        this.stuId = stuId;
    }

    public String getStuName() {
        return stuName;
    }

    public void setStuName(String stuName) {
        this.stuName = stuName;
    }

    public boolean isStuSex() {
        return stuSex;
    }

    public void setStuSex(boolean stuSex) {
        this.stuSex = stuSex;
    }

    //toString 方法
//    @Override
//    public String toString() {
//        return "Student{" +
//                "stuId=" + stuId +
//                ", stuName='" + stuName + '\'' +
//                ", stuSex=" + stuSex +
//                '}';
//    }

    public void sayHi(){
        System.out.println("大家好。");
        //匿名内部类（需要实现）     只使用一次，使用完成释放内存
        new Team(){
            @Override
            public void playGame() {
                System.out.println("我是匿名内部类");
            }
        }.playGame();
    }

}
